package org.ssssssss.magicapi.dubbo;

import org.apache.dubbo.spring.boot.autoconfigure.DubboRelaxedBindingAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.ssssssss.magicapi.core.config.MagicPluginConfiguration;
import org.ssssssss.magicapi.core.model.Plugin;

@Configuration
@EnableConfigurationProperties(MagicDubboProperties.class)
@AutoConfigureBefore({DubboRelaxedBindingAutoConfiguration.class})
public class MagicDubboConfiguration implements MagicPluginConfiguration {

    private final MagicDubboProperties dubboProperties;

    public MagicDubboConfiguration(MagicDubboProperties dubboProperties) {
        this.dubboProperties = dubboProperties;
    }

    /**
     * 注入Dubbo模块
     */
    @Bean
    @ConditionalOnMissingBean
    public DubboModule dubboModule(MagicDubboProperties magicDubboProperties) {
        return new DubboModule(magicDubboProperties);
    }

    @Override
    public Plugin plugin() {
        return new Plugin("Dubbo");
    }
}
